class BaseResponse:

    @classmethod
    def base_response(cls,code,data=None,msg=None):
        """Basic response"""

        r_data = {} if data is None else data
        r_msg = "" if msg is None else msg

        return {
            "code": code,
            "message": r_msg,
            "data": r_data
        }

    @classmethod
    def success(cls,data=None):
        """Success response"""
        return cls.base_response(0,msg="Success",data=data)

    @classmethod
    def fail(cls,fail_code,msg,data):
        """fail response"""
        return cls.base_response(code=fail_code,msg=msg,data=data)


class UnicornException(Exception):

    def __init__(self, code, errmsg, data=None):
        """
        失败返回格式
        :param status: code
        :param errmsg: 错误信息
        """
        self.code = code
        self.errmsg = errmsg
        self.data = {} if data is None else data
